home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
content
/
historyCategory.js
< prev
next >
Wrap
Text File
|
2009-09-29
|
12KB
|
341 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* historyCategory.js
* Responsible for category view
*/
bthistory.controllers["category"] = {
onHistoryAdd: function(dataset) {
if(!document.getElementById("column1")){
bthistory.updateView();
return;
}
bthistory.app.debug("category::onHistoryAdd");
var len = dataset.length;
var max = bthistory.app.glanceItemsPerPage;
for(var x = 0; x < len; x++){
var item = dataset[x];
if(item.type == "web" && len > 1){
break;
}
var box = document.getElementById("categorybox." + item.type);
if(!box){
var column = document.getElementById(
this.nextColumn ? "column1" : "column2");
this.loadCategory(item.type, [ item ], column, max);
this.nextColumn = !this.nextColumn;
} else {
var hbox = this.buildLineItemBox(item.type, item);
if(box.childNodes.length < max + 1){
box.insertBefore(hbox, box.firstChild.nextSibling);
} else if(box.childNodes.length == max + 1){
box.insertBefore(hbox, box.firstChild.nextSibling);
var hbox = this.buildMoreItemsBox(item.type);
box.appendChild(hbox);
} else {
box.insertBefore(hbox, box.firstChild.nextSibling);
box.removeChild(box.lastChild.previousSibling);
}
}
}
},
onHistoryChange: function(data) {
bthistory.app.debug("category::onHistoryChange");
},
handleUpArrow: function(){
var sels = document.getElementsByClassName("selected");
var body = document.getElementById("body");
var items = document.getElementsByClassName("historyItem");
if(items.length == 0){
return;
}
if(sels.length == 0){
var node = items[items.length - 1].parentNode;
bthistory.selectNode(node);
bthistory.scrollIntoView(body, node, 24);
} else {
var sel = sels[0];
var len = items.length;
for(var x = 0; x < len; x++){
if(sel == items[x].parentNode){
if(x > 0){
var node = items[x - 1].parentNode;
bthistory.selectNode(node);
bthistory.scrollIntoView(body, node, 24);
}
break;
}
}
}
},
handleDownArrow: function(){
var sels = document.getElementsByClassName("selected");
var body = document.getElementById("body");
var items = document.getElementsByClassName("historyItem");
if(items.length == 0){
return;
}
if(sels.length == 0){
var node = items[0].parentNode;
bthistory.selectNode(node);
bthistory.scrollIntoView(body, node, 24);
} else {
var sel = sels[0];
var len = items.length;
for(var x = 0; x < len; x++){
if(sel == items[x].parentNode){
if(x + 1 < len){
var node = items[x + 1].parentNode;
bthistory.selectNode(node);
bthistory.scrollIntoView(body, node, 24);
}
break;
}
}
}
},
handleResize: function(){
},
queryTracker: function(types, filter){
// usually web means all but for category, we really need all
if(types.length == 1 && types[0] == 'web'){
var alltypes = bthistory.app.tracker.types;
types = [];
for(var x in alltypes){
types.push(x);
}
}
return bthistory.storage.queryTrackerByCategory(
bthistory._range.start,
bthistory._range.end,
types,
filter,
bthistory.app.glanceItemsPerPage + 1,
false
);
},
loadView: function(){
var data = bthistory._data;
var types = bthistory.tracker.types;
var hasdata = false;
for(var x in types){
if(data.hasOwnProperty(x)){
hasdata = true;
break;
}
}
if(!hasdata){
var body = document.getElementById("body");
var label= document.createElement("label");
label.setAttribute("value", bthistory.app.getString("history.nodatafound"));
label.className = "nodatafound";
body.appendChild(label);
} else {
document.loadOverlay("chrome://boomtango/content/historyGlance.xul", this);
}
document.getElementById("bubble_back").setAttribute("hidden", "false");
},
observe: function(subject, topic, data) {
if(topic == "xul-overlay-merged"){
bthistory.app.log("historyGlance::overlayLoaded");
this.loadMergedView();
}
},
/*
loadMergedView is handled after view has been merged.
*/
loadMergedView: function() {
var body = document.getElementById("body");
body.setAttribute('style', 'border: none; padding: none;');
var data = bthistory._data;
var leftColumn = true;
var types = bthistory.tracker.types;
var max = bthistory.app.glanceItemsPerPage;
for(var x in types){
if(data.hasOwnProperty(x) && bthistory.app.getTrackerEnabled(x)){
var column = document.getElementById(
leftColumn ? "column1" : "column2");
this.loadCategory(x, data[x], column, max);
leftColumn = !leftColumn;
}
}
this.nextColumn = leftColumn;
document.getElementById("body_header").
setAttribute("hidden", "false");
// we've added stuff above the body element so we need a recalc
bthistory.resizeToWindow();
},
buildMoreItemsBox: function(type){
var hbox = document.createElement('hbox');
hbox.setAttribute("flex", "1");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
hbox.appendChild(spacer);
var linkNode = document.createElement("label");
linkNode.className = "text-link";
linkNode.setAttribute("value", bthistory.app.getString("category.moreitems"));
linkNode.setAttribute("crop", "end");
linkNode.addEventListener(
"click",
function(){
bthistory.handleMoreItems(type);
},
false
);
hbox.appendChild(linkNode);
return hbox;
},
buildLineItemBox: function(type, item){
var hbox = document.createElement('hbox');
var fi = Components.classes["@mozilla.org/browser/favicon-service;1"].getService(Components.interfaces.nsIFaviconService);
var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService2);
hbox.setAttribute("flex", "1");
hbox.setAttribute("contentID", item.ftsrowid);
hbox.setAttribute("trackerID", item.id);
var uri = io.newURI(item.url, null, null);
var iconURI = fi.getFaviconImageForPage(uri);
var img = document.createElement("image");
img.setAttribute("src", iconURI.spec);
img.className = "calendaricon";
var title = item.title || item.url;
var vbox = document.createElement('vbox');
var linkNode = document.createElement("label");
linkNode.className = "historyItem";
linkNode.setAttribute("value", title);
linkNode.setAttribute("crop", "end");
linkNode.setAttribute("flex", "1");
vbox.appendChild(img);
hbox.appendChild(vbox);
hbox.appendChild(linkNode);
label = document.createElement("label");
label.className = "text-link";
label.setAttribute("value", bthistory.datestring(item.starttime));
this.addStartClickHandler(label, item);
hbox.appendChild(label);
/*
vbox = document.createElement('vbox');
vbox.className = "closeBox";
vbox.id = "closebox." + item.ftsrowid;
vbox.style.visibility = "hidden";
vbox.addEventListener(
"click",
function(){
bthistory.handleDeleteHistoryItem(hbox, item.ftsrowid);
},
false
);
hbox.addEventListener(
"mouseover",
function(e){
var node = e.target;
var id = node.getAttribute ? node.getAttribute("contentID") : null;
while(!id){
node = node.parentNode;
if(!node || node.id == "body" || !node.getAttribute){
break;
}
id = node.getAttribute("contentID")
}
if(id){
var closebox = document.getElementById("closebox." + id);
if (closebox) {
closebox.style.visibility = "visible";
}
}
},
false
);
hbox.addEventListener(
"mouseout",
function(e){
var node = e.target;
var id = node.getAttribute ? node.getAttribute("contentID") : null;
while(!id){
node = node.parentNode;
if(!node || node.id == "body" || !node.getAttribute){
break;
}
id = node.getAttribute("contentID")
}
if(id){
var closebox = document.getElementById("closebox." + id);
if (closebox) {
closebox.style.visibility = "hidden";
}
}
},
false
);
img = document.createElement("image");
img.setAttribute("src", "chrome://boomtango/skin/close_icon.png");
vbox.appendChild(img);
hbox.appendChild(vbox);
*/
return hbox;
},
loadCategory: function(type, data, container, max){
if(data && data.length){
var name = type == "web" ? bthistory.app.getString("category.type.all")
: bthistory.app.tracker.types[type].name_plural;
var len = data.length;
var box = document.createElement("vbox");
box.className = "categorybox";
box.id = "categorybox." + type;
box.setAttribute("style", "border-color: " +
bthistory.app.getTrackerColor(type) + ";");
var label = document.createElement("label");
label.className = "topurl_title";
label.setAttribute("value", name);
box.appendChild(label);
for(var x = 0; x < data.length; x++){
if(x >= max){
var hbox = this.buildMoreItemsBox(type);
box.appendChild(hbox);
break;
}
var item = data[x];
var hbox = this.buildLineItemBox(type, item);
box.appendChild(hbox);
}
container.appendChild(box);
}
},
addStartClickHandler: function(linkNode, item){
linkNode.addEventListener(
"click",
function(){
bthistory.currTime = item.starttime;
bthistory.loadView('calendar', 'hour', item.ftsrowid);
},
false
);
},
QueryInterface: function(iid) {
if (iid.equals(bthistory.app.ci.nsIObserver) ||
iid.equals(bthistory.app.ci.nsISupports)) {
return this;
}
throw Components.result.NS_ERROR_NO_INTERFACE;
}
};